package com.example.smart_community.mapper;


import com.example.smart_community.po.Post;
import com.example.smart_community.po.Staff;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StaffMapper {
    @Select("select * from staff")
    @Results({
            @Result(property = "sId",column = "s_id"),
            @Result(property = "entryTime",column = "entry_time"),
            @Result(
                    property ="post" ,column ="postId",
                    javaType= Post.class,
                    one=@One(select ="com.example.smart_community.mapper.PostMapper.selectById")
            )
    })
    List<Staff> selectAll();
    @Select("select * from staff where s_id=#{sId}")
    @Results({
            @Result(property = "sId",column = "s_id"),
            @Result(property = "entryTime",column = "entry_time"),
            @Result(
                    property ="post" ,column ="postId",
                    javaType= Post.class,
                    one=@One(select ="com.example.smart_community.mapper.PostMapper.selectById")
            )
    })
    Staff selectById(Integer sId);
    @Select("select s_id,name,status from  staff where postId=#{postId}")
    @Results({
            @Result(property = "sId",column = "s_id"),
           @Result(property = "name",column = "name"),
            @Result(property = "status",column = "status")
    })
    List<Staff> selectByPostId(Integer postId);

    //动态查询
    List<Staff> selectByDynamic(@Param("name") String name,@Param("postId") Integer postId,@Param("entryTime1") String entryTime1,@Param("entryTime2") String entryTime2,@Param("address")String address);
    //动态修改
    int updateByDynamic(@Param("sId") Integer sId,@Param("name") String name,@Param("gender") String gender,@Param("entryTime") String entryTime,
                        @Param("status") Integer status,@Param("phone") String phone,@Param("address") String address,@Param("idcard") String idcard,@Param("postId") Integer postId

    );
    //添加员工
    @Insert("insert into staff (name,gender,entry_time,`status`,phone,address,idcard,postId,state) VALUES(#{name},#{gender},#{entryTime},#{status},#{phone},#{address},#{idcard},#{postId},#{state})")
    int insertStaff(
           @Param("name") String name,@Param("gender") String gender,@Param("entryTime") String entryTime,
            @Param("status") Integer status,@Param("phone") String phone,@Param("address") String address,@Param("idcard") String idcard,@Param("postId") Integer postId,
            @Param("state") Integer state
    );
    //删除员工
    @Update("UPDATE staff set state=#{state} where s_id=#{sId}")
    @Results({
            @Result(property = "sId",column = "s_id")
    })
    int updateByState(@Param("sId") Integer sId,@Param("state") Integer state);
}
